package shuashuami.hb.com.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import shuashuami.hb.com.avtivity.AbActivity;
import shuashuami.hb.com.hbclient.R;

/**
 * <b>类   名：</b>${TYPE_NAME} <br/>
 * <b>类描述：</b> <br/>
 * <b>创建人：</b>zhangqi<br/>
 * <b>创建时间：</b>2017/6/15<br/>
 * <b>修改人：</b>zhangqi<br/>
 * <b>修改时间：</b>2017/6/15<br/>
 * <b>修改备注：</b><br/>
 *
 * @version 1.0.0<br/>
 */
public abstract class AbFragment extends Fragment {

    private TextView my_status_bar;
    private RelativeLayout my_title_bar;
    private TextView titlebar_text;

    private View parentView;
    private ImageView btn_left;
    private ImageView btn_right;

    private TextView tv_right;


    public AbActivity getAbActivity(){

        return (AbActivity)getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        parentView = inflater.inflate(bindView(), container, false);
        return parentView;
    }

    public View findViewById(int id){

        return parentView.findViewById(id);
    }

    public void setRightTextView(String str) {
        if (tv_right == null) {
            tv_right = (TextView) findViewById(R.id.titlebar_next);
        }
        tv_right.setText(str);
        tv_right.setVisibility(View.VISIBLE);
    }

    public void setRightTextViewListener(View.OnClickListener listener) {
        tv_right.setOnClickListener(listener);
    }

    public View findSelfViewById(int id){
        return parentView.findViewById(id);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initData();
        initListener();

    }

    public void setLeftView(){
        if(btn_left==null){
            btn_left= (ImageView) parentView.findViewById(R.id.btn_left);
        }
        btn_left.setVisibility(View.VISIBLE);
    }

    public void setLeftView(int resId){
        setLeftView();
        btn_left.setImageResource(resId);

    }

    public void setLeftViewListener(View.OnClickListener listener){
        btn_left.setOnClickListener(listener);
    }

    public void setRightViewListener(View.OnClickListener listener){
        btn_right.setOnClickListener(listener);
    }

    public void setRightView(){
        if(btn_right==null){
            btn_right= (ImageView) parentView.findViewById(R.id.btn_right);
        }
        btn_right.setVisibility(View.VISIBLE);
    }
    public void setRightView(int resId){
        setRightView();
        btn_right.setImageResource(View.VISIBLE);

    }

    public void setTitleBarColor(int color) {
        my_status_bar.setBackgroundColor(color);
        my_title_bar.setBackgroundColor(color);
    }


    public void setTitleBar(String title,boolean isNormal){
        my_status_bar= (TextView) parentView.findViewById(R.id.my_status_bar);
        my_title_bar= (RelativeLayout) parentView.findViewById(R.id.my_title_bar);
        titlebar_text= (TextView) parentView.findViewById(R.id.titlebar_text);
        if(my_status_bar==null)return;
        titlebar_text.setText(title);
        if(isNormal){
            setTitleBarColor(getResources().getColor(R.color.app_main));
        }
    }



    public void setTitleBar(String title){
        setTitleBar(title,true);
    }


    public abstract void initView(View v);
    public abstract void initData();
    public abstract void initListener();
    public abstract int bindView();
}
